package moniCA::DBH::MySQL;

#################################################################
# $LastChangedDate: 2013-11-25 15:03:06 +0000 (Mon, 25 Nov 2013) $
# $LastChangedRevision: 22 $
# $LastChangedBy: aswod_83@gmx.net $
#################################################################
use strict;
use base qw /moniCA::LOGFILE::PARSE/;
use DBI;
use Data::Dumper;
use XML::Simple;

#-------------------------------------------------------------------------------
sub ConnectDB {

#-------------------------------------------------------------------------------
# Description:
# Input Parms:
# Output Parms:
#-------------------------------------------------------------------------------
    my $self   = shift;
    my $logger = $self->GetLogger();
    my $dbc    = $self->{CNF}->{DBConnect};
    my $db     = DBI->connect(
        $dbc->{ConnectString}, $dbc->{dbuser},
        $dbc->{dbpw}, { RaiseError => 1 }
    );
    $self->{DBH} = $db;
    return $self;
}

#-------------------------------------------------------------------------------
sub DisconnectDB {

#-------------------------------------------------------------------------------
# Description:
# Input Parms:
# Output Parms:
#-------------------------------------------------------------------------------
    my $self   = shift;
    my $logger = $self->GetLogger();
    $self->{DBH}->disconnect()
      || $logger->warn("$self->{DBH}->errstr");
    return $self;
}

#-------------------------------------------------------------------------------
sub get_bckp_stat {

#-------------------------------------------------------------------------------
# Description:
# Input Parms:
# Output Parms:
#-------------------------------------------------------------------------------
    my $self = shift;
    my $rc   = 0;
    if ( -f $self->{CNF}->{DBBackup}->{bckp_queue} ) {
        open FH, "$self->{CNF}->{DBBackup}->{bckp_queue}" or die $!;
        while ( my $line = <FH> ) {
            if ( $line =~ /aktiv/ ) {
                $rc++;
                last;
            }
        }
    }
    close FH;
    return $rc;
}

1;
